# -*- bazel -*-

load("@drake//tools/install:install.bzl", "install")
load("@drake//tools/skylark:cc.bzl", "cc_library")

licenses(["notice"])  # EPL-2.0

package(default_visibility = ["//visibility:private"])

cc_library(
    name = "csdp",
    srcs = [
        "lib/Fnorm.c",
        "lib/add_mat.c",
        "lib/addscaledmat.c",
        "lib/allocmat.c",
        "lib/calc_dobj.c",
        "lib/calc_pobj.c",
        "lib/chol.c",
        "lib/copy_mat.c",
        "lib/easysdp.c",
        "lib/freeprob.c",
        "lib/initparams.c",
        "lib/initsoln.c",
        "lib/linesearch.c",
        "lib/make_i.c",
        "lib/makefill.c",
        "lib/mat_mult.c",
        "lib/mat_multsp.c",
        "lib/matvec.c",
        "lib/norms.c",
        "lib/op_a.c",
        "lib/op_at.c",
        "lib/op_o.c",
        "lib/packed.c",
        "lib/psd_feas.c",
        "lib/qreig.c",
        "lib/readprob.c",
        "lib/readsol.c",
        "lib/sdp.c",
        "lib/solvesys.c",
        "lib/sortentries.c",
        "lib/sym_mat.c",
        "lib/trace_prod.c",
        "lib/tweakgap.c",
        "lib/user_exit.c",
        "lib/writeprob.c",
        "lib/writesol.c",
        "lib/zero_mat.c",
    ],
    hdrs = [
        "includes/csdp/blockmat.h",
        "includes/csdp/declarations.h",
        "includes/csdp/index.h",
        "includes/csdp/parameters.h",
    ],
    copts = [
        "-fvisibility=hidden",
        "-w",
        # CSDP calls exit() for error handling. That doesn't suit our needs for
        # embedding it within Drake, so we'll redirect calls to exit() to our
        # own setjmp/longjmp handler instead.
        "-Dexit=drake_csdp_cpp_wrapper_exit",
        # Because we use longjmp, we must forbid CSDP's OpenMP-based threads.
        "-fno-openmp",
    ],
    includes = ["includes"],
    isystem = True,
    linkstatic = 1,
    deps = [
        "@blas",
        "@drake//solvers:csdp_solver_error_handling",
        "@lapack",
    ],
    visibility = ["//visibility:public"],
)

# We do not install the header file (its a private dependency), but we still
# need to install its license file.
install(
    name = "install",
    docs = ["LICENSE"],
    visibility = ["//visibility:public"],
)

exports_files(["drake_repository_metadata.json"])
